<template>
  <div class="hello">
    <div id="cesiumContainer"></div>
  </div>
</template>

<script>
export default {
  name: "CesiumViewer",
  mounted() {
    var _this = this;
    /*初始化*/
    var viewer = new Cesium.Viewer('cesiumContainer', {
      sceneMode : Cesium.SceneMode.SCENE2D,
      timeline : false,
      animation : false
    });
    /*引入json*/
    var dataSource = Cesium.GeoJsonDataSource.load('/fenqu.geojson');
    viewer.dataSources.add(dataSource).then(function (data) {
      /*以下为智慧营区代码，没有起作用*/
     /* var entities = dataSource.entities.values;
      console.log(entities);
      entities.forEach(function(dex, val){
        val.parent = _this.globalEv.allPolygon;
        //设置颜色
        var r = Math.ceil(Math.random() * 255);
        var g = Math.ceil(Math.random() * 255);
        var b = Math.ceil(Math.random() * 255);
        var color = Cesium.Color.fromBytes(r, g, b, 50);
        val._polygon.material = color;
        val._polygon.extrudedHeight = 10;
        //计算中心点
        var polyPositions = val._polygon.hierarchy._value.positions;
        var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center;
        var poly1 = Cesium.Cartesian3.fromElements(polyCenter.x, polyCenter.y, polyCenter.z + 100);
        var labels = _this.GLOBAL.viewer.entities.add({
          parent: _this.globalEv.allPolygon,
          name: '区面',
          position: poly1, //从以度为单位的经度和纬度值返回Cartesian3位置
          label: {
            // height: 20,
            text: val._name,
            color: Cesium.Color.fromCssColorString('#ffff00'),
            font: 'normal 34px MicroSoft YaHei',
            scale: .5
          }
        });
      })*/
    });
    viewer.zoomTo(dataSource);



  }
};
</script>
